/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

/**
 *
 * @author James
 */
@Entity
public class Groupon implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private int  discount; // Same as item's discount but it would not be stacked. In other words, the final price will be calculated based on this discount and ORIGINAL price, not the DISCOUNTED item price.
    private int  minimumNumOfBuyersToBeValid;
    private int  currentNumOfBuyers;
    private long startDate;
    private long endDate;
    @ManyToOne
    private Partner thePartner;
    @OneToOne
    private Item theItem;
    @ManyToOne
    private TermsAndConditions theTerm;

    public void createGroupon(int discount, int minimumNumOfBuyersToBeValid, int currentNumOfBuyers, long startDate, long endDate, Partner thePartner, Item theItem, TermsAndConditions theTerm) {
        this.discount                    = discount;
        this.minimumNumOfBuyersToBeValid = minimumNumOfBuyersToBeValid;
        this.currentNumOfBuyers          = currentNumOfBuyers;
        this.startDate                   = startDate;
        this.endDate                     = endDate;
        this.thePartner                  = thePartner;
        this.theItem                     = theItem;
        this.theTerm                     = theTerm;
    }
    
    //Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getCurrentNumOfBuyers() {
        return currentNumOfBuyers;
    }

    public void setCurrentNumOfBuyers(int currentNumOfBuyers) {
        this.currentNumOfBuyers = currentNumOfBuyers;
    }

    public int getDiscount() {
        return discount;
    }

    public void setDiscount(int discount) {
        this.discount = discount;
    }

    public long getEndDate() {
        return endDate;
    }

    public void setEndDate(long endDate) {
        this.endDate = endDate;
    }

    public int getMinimumNumOfBuyersToBeValid() {
        return minimumNumOfBuyersToBeValid;
    }

    public void setMinimumNumOfBuyersToBeValid(int minimumNumOfBuyersToBeValid) {
        this.minimumNumOfBuyersToBeValid = minimumNumOfBuyersToBeValid;
    }

    public long getStartDate() {
        return startDate;
    }

    public void setStartDate(long startDate) {
        this.startDate = startDate;
    }

    public Item getItem() {
        return theItem;
    }

    public void setItem(Item theItem) {
        this.theItem = theItem;
    }

    public Partner getPartner() {
        return thePartner;
    }

    public void setPartner(Partner thePartner) {
        this.thePartner = thePartner;
    }

    public TermsAndConditions getTermsAndConditions() {
        return theTerm;
    }

    public void setTermsAndConditions(TermsAndConditions theTerm) {
        this.theTerm = theTerm;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Groupon)) {
            return false;
        }
        Groupon other = (Groupon) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Groupon[ id=" + id + " ]";
    }
    
}
